import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs'

export const useGlobalStore = defineStore('global', () => {
  // language 的值有两个 zh-cn english
  // state
  const language = ref('zh-cn')

  // 更改语言
  // actions
  const changeLanguage = (value: string) => {
    language.value = value
  }

  // 通过计算属性，获取当前国际化语言文件
  // getters
  const locale = computed(() => (language.value === 'zh-cn' ? zhCn : en))

  return {
    language,
    locale,
    changeLanguage
  }
})
